package com.xuzz.xrpc.spring.context.xml.schema;

import com.xuzz.xrpc.common.PropertyConfig;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

/**
 * @description:
 * @author: xuzz
 * @create: 2020-02-21 21:28
 */
public class ClusterElementParser implements BeanDefinitionParser {

    @Override
    public BeanDefinition parse(Element element, ParserContext parserContext) {

        PropertyConfigElementUtil.parsePropertyConfigFromElement(element);
        return null;
        /*RootBeanDefinition beanDefinition;
        if(!parserContext.getRegistry().containsBeanDefinition("propertyConfig")) {
            beanDefinition = new RootBeanDefinition();
            beanDefinition.setBeanClass(PropertyConfig.class);
            beanDefinition.setLazyInit(false);
        }
        else {
            beanDefinition =(RootBeanDefinition)parserContext.getRegistry().getBeanDefinition("propertyConfig");
        }

        String loadBalance = element.getAttribute("loadbalance");
        if(!StringUtils.isEmpty(loadBalance))
        {
            beanDefinition.getPropertyValues().addPropertyValue("loadBalance",loadBalance);
        }

        if(!parserContext.getRegistry().containsBeanDefinition("propertyConfig")) {
            parserContext.getRegistry().registerBeanDefinition("propertyConfig", beanDefinition);
        }

        return beanDefinition;*/
    }
}
